<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
require_once("Writer.php");
//Includes
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class veh_decommission_list extends Page
{
       public $lblmodel = null;
       public $lblmake = null;
       public $Label43 = null;
       public $Label38 = null;
       public $lblyear = null;
       public $lblplate = null;
       public $lblEmpName = null;
       public $lblEmpId = null;
       public $JTDivInfo = null;
       public $JTGroupBox2 = null;
       public $Label1 = null;
       public $imgInfo = null;
       public $lblCurrOd = null;
       public $Label48 = null;
       public $Label16 = null;
       public $lblEng = null;
       public $JTGroupBox1 = null;
       public $btnPrint = null;
       public $JTJavaScript1 = null;
       public $btnSearch = null;
       public $edtSearch = null;
       public $Image4 = null;
       public $Image2 = null;
       public $imgBack = null;
       public $JTDecomissionReport = null;
       public $hfVeh = null;
       public $btnExport = null;
       public $JTDecomissionList = null;
       public $JTSiteTheme1 = null;
       function imgInfoJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivInfo').Show();
       <?php

       }

       function btnPrintJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var veh = document.getElementById('hfVeh').value;
       window.open('veh_decommission_print.php?veh='+veh,'popup','width=850,height=768,scrollbars=yes,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0');
       <?php

       }

       function btnPrintJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['btnPrint'].src="image/btn_print.png";
       <?php

       }

       function btnPrintJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['btnPrint'].src="image/btn_print2.png";
       <?php

       }

       function btnSearchClick($sender, $params)
       {
       redirect('veh_decommission_list.php?veh='.$this->hfVeh->getValue());
       }

       function edtSearchJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('edtSearch').value = '';
       <?php

       }

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }

       function btnExportClick($sender, $params)
       {
       $this->JTDecomissionReport->exportGridToXLSDownload('decommission_history_list.xls');
       }

       function btnExportJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['btnExport'].src="image/excel.png"
       <?php

       }

       function btnExportJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['btnExport'].src="image/excel2.png"
       <?php

       }

       function veh_decommission_listCreate($sender, $params)
       {
       $veh_id = $_GET['veh'];
       $this->hfVeh->setValue($veh_id);

       $result_vin = mysql_query("SELECT * FROM vehicle_tbl WHERE vehicle_id='".$this->hfVeh->getValue()."'");
       $row_selected = mysql_fetch_array($result_vin);
       $label = $row_selected['VIN'];
       $this->lblyear->Caption = $row_selected['year'];
       $this->lblmake->Caption = $row_selected['manufacturer_name'];
       $this->lblmodel->Caption = $row_selected['model_name'];
       $this->lblCurrOd->Caption = $row_selected['curr_tracking_value'];
       $this->lblplate->Caption = $row_selected['veh_num'];
       $this->lblEng->Caption = $row_selected['engine_model'];




       $this->imgBack->setLink('vehicle_list.php?company='.$_SESSION['company_id']);
       }


       function JTDecomissionListShow($sender, $params)
       {
       $veh_id = $this->hfVeh->getValue();
       $query_list = "SELECT * FROM veh_decommission WHERE veh_id='".$veh_id."' and
       (dec_date like '%".$this->edtSearch->Text."%'
       or end_date like '%".$this->edtSearch->Text."%'
       or reason like '%".$this->edtSearch->Text."%')order by dec_date DESC, autoid DESC";
       $result_list = mysql_query($query_list) or die("LIST ".mysql_error());

       $result_vin = mysql_query("SELECT * FROM vehicle_tbl WHERE vehicle_id='".$this->hfVeh->getValue()."'");
       $row_selected = mysql_fetch_array($result_vin);

       $grid_arr = array();
       $grid_report_arr = array();

       $grid_report_arr[] = array(
        '1' => "Plate: ".$row_selected['veh_num'],
        '2' => " ",
        '3' => " "
        );

       /*$grid_report_arr[] = array(
        '1' => "Year: ".$row_selected['year'],
        '2' => " ",
        '3' => " "
        );*/

       $grid_report_arr[] = array(
        '1' => "Model: ".$row_selected['manufacturer_name'].' '.$row_selected['model_name'].' '.$row_selected['year'],
        '2' => " ",
        '3' => " "
        );

       /*$grid_report_arr[] = array(
        '1' => "Model: ".$row_selected['model_name'],
        '2' => " ",
        '3' => " "
        ); */

       $grid_report_arr[] = array(
        '1' => " ",
        '2' => " ",
        '3' => " "
        );

       $grid_report_arr[] = array(
        '1' => "DECOMMISSION HISTORY",
        '2' => " ",
        '3' => " "
        );

       $grid_report_arr[] = array(
        '1' => "Start Date",
        '2' => "End Date",
        '3' => "Reason"
        );

       while($row_list = mysql_fetch_array($result_list))
       {
        $autoid = $row_list['autoid'];
        $date = $row_list['dec_date'];
        $end_date = $row_list['end_date'];
        $reason = $row_list['reason'];
        $tools = "<img src='image/delete.png' style='cursor:pointer;' onclick=js_delete('".$veh_id."','".$autoid."') />";
        $date_up = "<span style='cursor:pointer;color:blue;text-decoration:underline;' onclick=window.location.href='veh_decommission_edit.php?autoid=".$autoid."&veh=".$veh_id."'>".$date."</span>";

        //<img onclick=window.open('veh_decommission_print.php?veh=".$this->hfVeh->getValue()."','popup','width=850,height=768,scrollbars=yes,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); src='image/print.png' title='Print' style='cursor:pointer'>
       if($_SESSION["access_vehicle"]==1)
       {
        $grid_arr[] = array(
        'Start Date' => $date_up,
        'End Date' => $end_date,
        'Reason' => $reason
        );
       }
       if($_SESSION["access_vehicle"]==2)
       {
        $grid_arr[] = array(
        'Start Date' => $date_up,
        'End Date' => $end_date,
        'Reason' => $reason,
        'Tools' => $tools
        );
       }
        $grid_report_arr[] = array(
        '1' => $date,
        '2' => $end_date,
        '3' => $reason
        );
       }

       $this->JTDecomissionList->setCellData($grid_arr);
       $this->JTDecomissionReport->setCellData($grid_report_arr);
       }

}

global $application;

global $veh_decommission_list;

//Creates the form
$veh_decommission_list=new veh_decommission_list($application);

//Read from resource file
$veh_decommission_list->loadResource(__FILE__);

//Shows the form
$veh_decommission_list->show();

?>